<!DOCTYPE html>  
<html>  
<head>  
	<meta charset="utf-8"/>
	<title>变量提升</title>  
	<style type="text/css">  
	body{margin:0;padding:0;}  
	#wrap{width:300px;height:200px;border:1px solid #FFFFCC;background-color:#CCFFFF;position:absolute;}  
	#moveHere{cursor: move;width:300px;height: 30px;text-align: center;line-height:30px;background-color:#FFCCCC;}
	 
	</style>
</head>
<body>
<div id="wrap"></div>

<script type="text/javascript">

	console.log(xx());
	
	function xx() {
		console.log('这是xx方法');
	}

	var log = function(c) {
		var p_dom = document.createElement('p');
		p_dom.innerHTML = c;
		
		document.getElementById("wrap").appendChild(p_dom);
	}

	var a=1;
	function test(){
		log(a);  //undefined
		var a=1;
	}
	test();


	var b=2;
	function test2(){
	    b=22;  //若函数内没有定义b,则这里的b是全局变量b,若有定义，则是函数内部 的变量
		log(this.b); //2
		log(b);  //22
		var b;
	    
	}
	test2();


	c=5; 
	function test3(){
		window.c=3;
		log(c,'====c====');
		var c;
		log(window.c,'===window.c====');
	}
	test3();

</script>  
</body>  
</html>  